//
//  Screen.swift
//  CarSales
//
//  Created by cabinzhao on 3/2/17.
//  Copyright © 2017 玖融网. All rights reserved.
//

import Foundation
import UIKit

//屏幕宽度
let S_Width = UIScreen.main.bounds.width
//屏幕高度
let S_Height = UIScreen.main.bounds.height
//导航栏宏高度，适配Iphone X
let NAV_HT:CGFloat = (UIScreen.main.bounds.height == 812.0) ? 88 : 64
let SB_HT:CGFloat = (UIScreen.main.bounds.height == 812.0) ? 44 : 20

let iphone5  = UIScreen.instancesRespond(to:#selector(getter: UIScreen.main.currentMode)) ? __CGSizeEqualToSize(CGSize(width:960,height:1336), (UIScreen.main.currentMode?.size)!) : false
let iphone6  = UIScreen.instancesRespond(to:#selector(getter: UIScreen.main.currentMode)) ? __CGSizeEqualToSize(CGSize(width:750,height:1334), (UIScreen.main.currentMode?.size)!) : false
let iphone6p  = UIScreen.instancesRespond(to:#selector(getter: UIScreen.main.currentMode)) ? __CGSizeEqualToSize(CGSize(width:1242,height:2208), (UIScreen.main.currentMode?.size)!) : false
let iphone6pBigMode = UIScreen.instancesRespond(to:#selector(getter: UIScreen.main.currentMode)) ? __CGSizeEqualToSize(CGSize(width:1125,height:2001), (UIScreen.main.currentMode?.size)!) : false
let iphoneX = UIScreen.instancesRespond(to:#selector(getter: UIScreen.main.currentMode)) ? __CGSizeEqualToSize(CGSize(width:1125,height:2436), (UIScreen.main.currentMode?.size)!) : false

//适配参数
let suitParm:CGFloat = (iphone6p ? 1.12 : (iphone6 ? 1.0 : (iphone6pBigMode ? 1.01 : (iphoneX ? 1.0 : 0.85))))
//xib自动约束
extension NSLayoutConstraint {
    @IBInspectable var adapterScreen: Bool {
        get {
            return true
        }
        set {
            if newValue {
                self.constant = self.constant * suitParm
            }
        }
    }
}

class Screen {
    static let width = UIScreen.main.bounds.width
    static let height = UIScreen.main.bounds.height
    //UI设计图标准高宽 375 667
    static var UI_WIDTH:CGFloat = 375
    static var UI_HEIGHT:CGFloat = 667
    //屏幕适配宽度比例系数
    static let widthRatio:CGFloat = width / UI_WIDTH
    //屏幕适配比例系数 高度
    //minus 为不拉伸部分 0 代表全部拉伸
    //                20 不拉伸状态栏
    //                64 不拉伸状态栏+导航栏
    //               108 不拉伸状态栏+导航栏+Tab
    static var minusOffset:CGFloat = 0
    static var heightRatio:CGFloat {
        get {
            return (height - minusOffset) / (UI_HEIGHT - minusOffset)
        }
    }
}
